package com.labbit.platform.manager.controller;

import com.labbit.platform.commons.constants.APIModules;
import com.labbit.platform.commons.domain.vo.Result;
import com.labbit.platform.commons.session.SessionData;
import com.labbit.platform.manager.domain.bo.LoginBO;
import com.labbit.platform.manager.service.AdminUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: 登录控制器
 * @Author: CHEN YU
 * @Date: 2019-07-28 20:12
 **/
@Api(tags = APIModules.USER_MODULES)
@RestController
@RequestMapping("login")
@Slf4j
public class LoginController {

    @Autowired
    private AdminUserService userService;


    @ApiOperation(value = "登录方法", notes = "登录返回token, 以后每次访问放到header里面，key为token")
    @PostMapping
    public Result login(@Validated LoginBO loginBO) {
        log.info("User login: {}", loginBO.getUsername());
        SessionData sessionData = userService.login(loginBO.getUsername(), loginBO.getUsername());
        return Result.success(sessionData);
    }

}
